package com.longshihan.module_sample.huazhu.mvp.presenter;

import android.content.Context;

import com.longshihan.module_sample.huazhu.mvp.contract.LoadingContract;
import com.longshihan.module_sample.huazhu.mvp.model.entity.AppEntity;
import com.longshihan.module_sample.huazhu.mvp.model.entity.HuaZhuJsonObject;
import com.longshihan.module_sample.huazhu.mvp.model.impl.ILoading;
import com.longshihan.module_sample.huazhu.mvp.model.impl.LoadingImpl;
import com.longshihan.mvplh.mvp.BasePresenter;
import com.longshihan.mvplh.utils.ArmsUtils;
import com.orhanobut.logger.Logger;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by LONGHE001.
 *
 * @time 2017/11/21 0021
 * @des
 * @function
 */

public class LoadingPresenter extends BasePresenter<LoadingContract.View> implements LoadingContract.Presenter {
    private ILoading mIModel;
    private Context context;
    public LoadingPresenter(Context context) {
        mIModel = new LoadingImpl(ArmsUtils.obtainAppComponentFromContext(context).repositoryManager());
    }
    @Override
    public void fetch(String addressId) {
        Disposable disposable = mIModel.loadData(addressId)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<HuaZhuJsonObject<AppEntity>>() {
                    @Override
                    public void accept(HuaZhuJsonObject<AppEntity> appEntityHuaZhuJsonObject) throws Exception {
                        Logger.d("测试",appEntityHuaZhuJsonObject.Message);


                    }
                });
        addDispose(disposable);
    }
}
